package com.arquitecture.form;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import com.architecture.entity.Entity;

/**
 * <p>Represents the data that comes from view</p>
 * @author JR
 * @param <E>
 */
public abstract class Form<E extends Entity> {
	
	private E view;
	private Collection<E> collection;
	
	@SuppressWarnings("unchecked")
	public Form() {
		Type[] types = ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments();
		Class<E> clazz = (Class<E>)types[0];
		try {
			this.setView(clazz.newInstance());
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
	
	/**
	 * @return the view
	 */
	public E getView() {
		return view;
	}
	/**
	 * @param view the view to set
	 */
	public void setView(E view) {
		this.view = view;
	}
	/**
	 * @return the collection
	 */
	public Collection<E> getCollection() {
		return collection;
	}
	/**
	 * @param collection the collection to set
	 */
	public void setCollection(Collection<E> collection) {
		this.collection = collection;
	}

}
